import GROUP_DATA from '../../utils/groups.js'

Page({
  data: {
    groupId: null,
    groupInfo: {
      name: '',
      wordCount: 0
    }
  },

  onLoad(options) {
    const groupId = options.groupId;
    // 从groups.js获取分组信息
    const groupData = GROUP_DATA.find(item => item.group.group_id === groupId);
    
    if (groupData) {
      this.setData({
        groupId,
        groupInfo: {
          name: groupData.group.word_chinese,
          wordCount: groupData.words.length
        }
      });
    }
  },

  onShow() {
    // 获取所有正在播放的音频上下文并停止它们
    const audioContexts = wx.getBackgroundAudioManager();
    if (audioContexts) {
      audioContexts.stop();
    }

    // 停止所有 InnerAudioContext
    const innerAudioContext = wx.createInnerAudioContext();
    if (innerAudioContext) {
      innerAudioContext.stop();
    }
  },

  goToTest(e) {
    const testType = e.currentTarget.dataset.type;
    const pages = {
      listening: '/pages/listeningTest/listeningTest',
      recognition: '/pages/recognitionTest/recognitionTest',
      speaking: '/pages/speakingTest/speakingTest'
    };

    wx.navigateTo({
      url: `${pages[testType]}?groupId=${this.data.groupId}`
    });
  }
}); 